package com.sysef.util;

import java.sql.ResultSet;
import java.sql.SQLException;

public class DaoTools {

	public static Integer getInteger(ResultSet rs, String strColName) throws SQLException {
		return (Integer) getObject(rs, strColName);
	}

	public static Integer getInteger(ResultSet rs, int intColIndex) throws SQLException {
		return (Integer) getObject(rs, intColIndex);
	}

	public static Long getLong(ResultSet rs, String strColName) throws SQLException {
		return (Long) getObject(rs, strColName);
	}

	public static Long getLong(ResultSet rs, int intColIndex) throws SQLException {
		return (Long) getObject(rs, intColIndex);
	}

	public static Double getDouble(ResultSet rs, String strColName) throws SQLException {
		return (Double) getObject(rs, strColName);
	}

	public static Double getDouble(ResultSet rs, int intColIndex) throws SQLException {
		return (Double) getObject(rs, intColIndex);
	}

	public static Float getFloat(ResultSet rs, String strColName) throws SQLException {
		return (Float) getObject(rs, strColName);
	}

	public static Float getFloat(ResultSet rs, int intColIndex) throws SQLException {
		return (Float) getObject(rs, intColIndex);
	}

	public static Boolean getBoolean(ResultSet rs, String strColName) throws SQLException {
		return (Boolean) getObject(rs, strColName);
	}

	public static Boolean getBoolean(ResultSet rs, int intColIndex) throws SQLException {
		return (Boolean) getObject(rs, intColIndex);
	}

	private static Object getObject(ResultSet rs, String strColName) throws SQLException {
		Object nValue = rs.getObject(strColName);
		if (rs.wasNull()) {
			return null;
		}
		return nValue;
	}

	private static Object getObject(ResultSet rs, int intColIndex) throws SQLException {
		Object nValue = rs.getObject(intColIndex);
		if (rs.wasNull()) {
			return null;
		}
		return nValue;
	}

}
